From e48cf1af6cccba3234c9175c9ce295e0219ce44a Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Mon, 22 Jul 2024 13:21:05 -0600 Subject: [PATCH] correct computation of timestamp with garmin real time positioning. (#1302) * correct computation of timestamp with garmin real time positioning. * tweak garmin pvt conversion --- garmin.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/garmin.cc b/garmin.cc index 29036fd3e..ca642c3e7 100644 --- a/garmin.cc +++ b/garmin.cc @@ -22,7 +22,7 @@ #include "garmin.h" #include // for INT_MAX -#include // for atan2, floor, sqrt +#include // for atan2, modf, sqrt #include // for fprintf, fflush, snprintf, snprintf #include // for int32_t #include // for strtol @@ -36,7 +36,7 @@ #include // for QString #include // for QTextCodec #include // for CaseInsensitive -#include // for qPrintable, foreach +#include // for qPrintable, qRound64, Q_INT64_C, qint64 #include "defs.h" #include "formspec.h" // for FormatSpecificDataList @@ -596,11 +596,13 @@ GarminFormat::pvt2wpt(GPS_PPvt_Data pvt, Waypoint* wpt) * 3) The number of leap seconds that offset the current UTC and GPS * reference clocks. */ - double wptime = 631065600.0 + pvt->wn_days * 86400.0 + - pvt->tow - - pvt->leap_scnds; - double wptimes = floor(wptime); - wpt->SetCreationTime(wptimes, 1000000.0 * (wptime - wptimes)); + double tow_integral_part; + double tow_fractional_part = modf(pvt->tow, &tow_integral_part); + qint64 seconds = Q_INT64_C(631065600) + pvt->wn_days * Q_INT64_C(86400) + + qRound64(tow_integral_part) + - pvt->leap_scnds; + qint64 milliseconds = qRound64(1000.0 * tow_fractional_part); + wpt->SetCreationTime(seconds, milliseconds); /* * The Garmin spec fifteen different models that use a different -- 2.30.2